package com.xgpro.mobile.studycentre.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xgpro.common.enums.ResultCodeEnum;
import com.xgpro.common.exceptions.BusinessRuntimeException;
import com.xgpro.common.service.BaseService;
import com.xgpro.common.utils.DDMsgUtil;
import com.xgpro.common.utils.ExcelExporeUtil;
import com.xgpro.common.utils.ReadPropertiesUtil;
import com.xgpro.common.utils.SendMsgUtil;
import com.xgpro.domain.rolemanage.entity.Department;
import com.xgpro.domain.studycentre.entity.DaiTuTea;
import com.xgpro.domain.studycentre.entity.StuEVA;
import com.xgpro.domain.studycentre.entity.TeaEVA;
import com.xgpro.domain.studycentre.entity.TeacherStudent;
import com.xgpro.domain.studycentre.vo.*;
import com.xgpro.domain.talentintroduction.dto.UserMessage;
import com.xgpro.domain.talentintroduction.entity.User;
import com.xgpro.mapper.rolemanage.DepartmentMapper;
import com.xgpro.mapper.studycentre.DaiTuTeaMapper;
import com.xgpro.mapper.studycentre.StuEvaMapper;
import com.xgpro.mapper.studycentre.TeaEvaMapper;
import com.xgpro.mapper.studycentre.TeacherAndStudentMapper;
import com.xgpro.mapper.talentintroduction.UserMapper;
import com.xgpro.mobile.studycentre.service.TeacherService;
import com.xgpro.pc.rolemanage.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author tx
 * @version 1.0
 * @date 2019/8/28 21:29
 */
@Service
@Transactional(readOnly = false)
public class TeacherServiceImpl extends BaseService implements TeacherService {
    /**
     *老师评价标志
     */
    private static  final Integer TEA_EVAKIND=0;

    /**
     * 申请导师状态
     */
    private static  final Integer APPLYTEA_STATUS=0;

    /**
     * 已有导师状态
     */
    private static  final Integer HADTEA_STATUS=1;

    /**
     * 导师带徒数
     */
    private static  final Integer STU_NUM_OVER=3;

    /**
     * 驳回申请
     */
    private static  final Integer FAILTEA_STATUS=2;

    /**
     * 操作失败
     */
    private static  final Integer FAIL_RESULT=0;


    @Resource
    private TeacherAndStudentMapper teacherAndStudentMapper;
    @Resource
    private DaiTuTeaMapper daiTuTeaMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private DepartmentMapper departmentMapper;
    @Resource
    private StuEvaMapper stuEvaMapper;
    @Resource
    private TeaEvaMapper teaEvaMapper;
    @Resource
    private DDMsgUtil ddMsgUtil;
    @Resource
    private UserService userService;
    /**
     * 显示导师下的学生
     * @param teaId
     * @return
     */
    @Override
    public List<StudentBack> qryStudentsByTeacherId(Integer teaId) {
        List<StudentBack> studentBacks = teacherAndStudentMapper.selectStudentByTeaId(teaId);
        return studentBacks;
    }

    /**
     * 查询个人信息
     * @param id
     * @return
     */
    @Override
    public UserInfoTS qryUserInfoById(Integer id) {
        UserInfoTS userInfo = teacherAndStudentMapper.qryUserInfoById(id);
        return userInfo;
    }

    /**
     * 解除关系
     * @param relationship
     * @return
     */
    @Override
    public Integer cancelRelationship(Relationship relationship) {
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("teaId",relationship.getTeaId());
        criteria.andEqualTo("stuId",relationship.getStuId());
        TeacherStudent teacherStudent = new TeacherStudent();
        teacherStudent.setCancleFlag(relationship.getCancleFlag());
        int result =0;
        if(teacherAndStudentMapper.selectByExample(example).get(0).getStatus().equals(HADTEA_STATUS)){
            result=teacherAndStudentMapper.updateByExampleSelective(teacherStudent, example);
        }
        return result;
    }

    /**
     * 解除关系确认
     * @param teaId
     * @param stuId
     * @return
     */
    @Override
    public Integer sureCancle(Integer teaId,Integer stuId){
            Integer result=0;
            Example example2 = new Example(DaiTuTea.class);
            example2.createCriteria().andEqualTo("userId",teaId);
            List<DaiTuTea> daiTuTeas = daiTuTeaMapper.selectByExample(example2);
            if(daiTuTeas==null||daiTuTeas.size()==0){
                throw new BusinessRuntimeException(ResultCodeEnum.CANCLE_FALE02.getCode(),ResultCodeEnum.CANCLE_FALE02.getMessage());
            }
            DaiTuTea daiTuTea = daiTuTeas.get(0);
            daiTuTea.setStuNum(daiTuTea.getStuNum()-1);
            Example example = new Example(TeacherStudent.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("teaId",teaId);
            criteria.andEqualTo("stuId",stuId);
            result=teacherAndStudentMapper.deleteByExample(example);
            if(result==0){
                throw new BusinessRuntimeException(ResultCodeEnum.ADD_FAILE.getCode(),ResultCodeEnum.ADD_FAILE.getMessage());
            }
            result=daiTuTeaMapper.updateByPrimaryKeySelective(daiTuTea);
            if(result==0){
            throw new BusinessRuntimeException(ResultCodeEnum.ADD_FAILE.getCode(),ResultCodeEnum.ADD_FAILE.getMessage());
            }
            return result;
    }

    /**
     * 解除关系取消
     * @param teaId
     * @param stuId
     * @return
     */
    @Override
    public Integer noSureCancle(Integer teaId,Integer stuId){
        Integer result=0;
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("teaId",teaId);
        criteria.andEqualTo("stuId",stuId);
        TeacherStudent teacherStudent = new TeacherStudent();
        teacherStudent.setCancleFlag(0);
        result=teacherAndStudentMapper.updateByExampleSelective(teacherStudent,example);
        if(result==0){
            throw new BusinessRuntimeException(ResultCodeEnum.ADD_FAILE.getCode(),ResultCodeEnum.ADD_FAILE.getMessage());
        }
        return result;
    }




    /**
     * 评价
     * @param evaluation
     * @return
     */
    @Override
    public Integer evaluation(Evaluation evaluation) {
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("teaId",evaluation.getTeaId());
        criteria.andEqualTo("stuId",evaluation.getStuId());
        TeacherStudent teacherStudent = new TeacherStudent();
        //老师评价
        if(evaluation.getEvaKind().equals(TEA_EVAKIND)){
            teacherStudent.setTeaEvaluation(evaluation.getEvaluation());
            teacherStudent.setTeaEvaTime(new Date());
        }else{
            teacherStudent.setStuEvaluation(evaluation.getEvaluation());
            teacherStudent.setStuEvaTime(new Date());
        }
        int result = teacherAndStudentMapper.updateByExampleSelective(teacherStudent, example);
        return result;
    }

    /**
     * 根据学生信息查询导师信息
     * @param id
     * @return
     */
    @Override
    public UserInfoTS qryTeacherByStudentId(Integer id) {
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stuId",id);
        criteria.andEqualTo("status",1);
        List<TeacherStudent> teacherStudents = teacherAndStudentMapper.selectByExample(example);
        if(teacherStudents!=null&&teacherStudents.size()>0){
            TeacherStudent teacherStudent = teacherStudents.get(0);
            UserInfoTS userInfoTS = qryUserInfoById(teacherStudent.getTeaId());
            return  userInfoTS;
        }else{
            return null;
        }
    }

    /**
     * 查询合适带徒的导师
     * @return
     */
    @Override
    public List<DaiTuTeaSimple> qryTeaSimple(String name) {
        List<DaiTuTeaSimple> daiTuTeaSimples = teacherAndStudentMapper.qryTeaSimple(name);
        return daiTuTeaSimples;
    }

    @Resource
    private SendMsgUtil sendMsgUtil;
    /**
     * 一键申请导师
     * @param userId
     * @return
     */
    @Override
    public Integer applayTea(Integer userId,Integer teaId) throws Exception {
        if(userId.equals(teaId)){
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_SELF.getCode(),ResultCodeEnum.TEA_SELF.getMessage());
        }
        Example example = new Example(TeacherStudent.class);
        example.createCriteria().andEqualTo("stuId",userId);
        List<TeacherStudent> teacherStudents = teacherAndStudentMapper.selectByExample(example);
        TeacherStudent teacherStudentModel=new TeacherStudent();
        if(teacherStudents!=null&&teacherStudents.size()>0){
            //没有记录
            for (TeacherStudent teacherStudent : teacherStudents) {
                if(teacherStudent.getStatus().equals(APPLYTEA_STATUS)){
                    //有申请状态
                    throw new BusinessRuntimeException(ResultCodeEnum.APPLAYTEA_FALE01.getCode(),ResultCodeEnum.APPLAYTEA_FALE01.getMessage());
                }
                if(teacherStudent.getStatus().equals(HADTEA_STATUS)){
                    //有导师状态
                    throw new BusinessRuntimeException(ResultCodeEnum.APPLAYTEA_FALE02.getCode(),ResultCodeEnum.APPLAYTEA_FALE02.getMessage());
                }
                if(teacherStudent.getStatus().equals(FAILTEA_STATUS)&&teacherStudent.getTeaId().equals(teaId)){
                    //拒绝状态
                    throw new BusinessRuntimeException(ResultCodeEnum.APPLAYTEA_FALE03.getCode(),ResultCodeEnum.APPLAYTEA_FALE03.getMessage());
                }
            }
        }
        teacherStudentModel.setTeaId(teaId);
        teacherStudentModel.setStuId(userId);
        teacherStudentModel.setApplyTime(new Date());
        Example example2 = new Example(DaiTuTea.class);
        example2.createCriteria().andEqualTo("userId",teaId);
        int result=0;
        if(daiTuTeaMapper.selectByExample(example2).get(0).getStuNum()<STU_NUM_OVER){
            result = teacherAndStudentMapper.insertSelective(teacherStudentModel);
            List<Integer> ids = new ArrayList<Integer>();
            ids.add(teacherStudentModel.getTeaId());
            sendMsgUtil.sendMsg(3,ReadPropertiesUtil.readUrl("tea_confirm"),ReadPropertiesUtil.readUrl("tea_message"),ids);
            String s = userService.selectAllUserId(ids);
            ddMsgUtil.sendMsg(s,ReadPropertiesUtil.readUrl("tea_message"));
        }
        return result;
    }

    /**
     * 查询徒弟申请状态
     * @param teaId
     * @param status
     * @return
     */
    @Override
    public List<StuSimple> qryStuSimpleByStatus(Integer teaId, Integer status) {
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("teaId",teaId);
        criteria.andEqualTo("status",status);
        List<TeacherStudent> teacherStudents = teacherAndStudentMapper.selectByExample(example);
        List<StuSimple> stuSimpleList=new ArrayList<StuSimple>();
        StuSimple stuSimple = null;
        String teaName = userMapper.selectByPrimaryKey(teaId).getUsername();
        ArrayList<Integer> stuIdList = new ArrayList<>();
        if(teacherStudents!=null&&teacherStudents.size()>0){
            for (TeacherStudent teacherStudent : teacherStudents) {
                stuSimple=new StuSimple();
                stuSimple.setApplyTime(teacherStudent.getApplyTime());
                stuSimple.setStatus(teacherStudent.getStatus());
                stuSimple.setStuId(teacherStudent.getStuId());
                //解除状态
                stuSimple.setCancleFlag(teacherStudent.getCancleFlag());
                stuSimple.setTeaName(teaName);
                stuSimpleList.add(stuSimple);
                stuIdList.add(teacherStudent.getStuId());
            }
        }
        List<UserMessage> userMessages =null;
        if(stuIdList.size()>0){
            userMessages=userMapper.selectByList(stuIdList);
        }
        if(userMessages!=null){
            for (UserMessage userMessage : userMessages) {
                for (StuSimple simple : stuSimpleList) {
                    if(simple.getStuId().equals(userMessage.getId())){
                        simple.setStuName(userMessage.getUsername());
                        simple.setDeptName(userMessage.getDeptname());
                    }
                }
            }
        }
        return    stuSimpleList;
    }

    /**
     * 处理申请
     * @param stuId
     * @return
     */
    @Override
    public Integer dealApplay(Integer stuId,Integer status,Integer teaId) {
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stuId",stuId);
        criteria.andEqualTo("teaId",teaId);
        TeacherStudent teacherStudent = new TeacherStudent();
        teacherStudent.setStatus(status);
        Integer result=0;
        if(status.equals(FAILTEA_STATUS)){
            result=teacherAndStudentMapper.updateByExampleSelective(teacherStudent,example);
        }
        if(status.equals(HADTEA_STATUS)){
            Example e=new Example(TeacherStudent.class);
            e.createCriteria().andEqualTo("stuId",stuId);
            e.createCriteria().andEqualTo("teaId",teaId);
            Integer statusHad=teacherAndStudentMapper.selectByExample(e).get(0).getStatus();
            if(statusHad!=0){
                throw new BusinessRuntimeException(ResultCodeEnum.APPLAYTEA_FALE04.getCode(),ResultCodeEnum.APPLAYTEA_FALE04.getMessage());
            }
            Integer passResult = teacherAndStudentMapper.passStudent(stuId, teaId, status);
            if(passResult.equals(FAIL_RESULT)){
                throw new BusinessRuntimeException(ResultCodeEnum.ARRNUM_FALE.getCode(),ResultCodeEnum.ARRNUM_FALE.getMessage());
            }
            Example example2 = new Example(DaiTuTea.class);
            example2.createCriteria().andEqualTo("userId",teaId);
            DaiTuTea daiTuTea = daiTuTeaMapper.selectByExample(example2).get(0);
            daiTuTea.setStuNum(daiTuTea.getStuNum()+1);
            result=daiTuTeaMapper.updateByExampleSelective(daiTuTea,example2);
            if(result==1){
                if(daiTuTeaMapper.selectByExample(example2).get(0).getStuNum()>=3){
                    //招徒已满,将其余申请置为未通过
                    Example example3=new Example(TeacherStudent.class);
                    Example.Criteria example3Criteria = example3.createCriteria();
                    example3Criteria.andEqualTo("teaId",teaId);
                    example3Criteria.andEqualTo("status",APPLYTEA_STATUS);
                    TeacherStudent teacherStudent2 = new TeacherStudent();
                    teacherStudent2.setStatus(FAILTEA_STATUS);
                    teacherAndStudentMapper.updateByExampleSelective(teacherStudent2,example3);
                }
            }
        }
        return result;
    }

    /**
     * 解除关系学生数
     * @param teaId
     * @return
     */
    @Override
    public Integer countStudents(Integer teaId) {
        return teacherAndStudentMapper.countStudents(teaId);
    }

    /**
     * 老师解除关系
     * @param studentId
     * @return
     */
    @Override
    public Integer countTeacher(Integer studentId) {
        Integer result=0;
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stuId",studentId);
        criteria.andEqualTo("cancleFlag",1);
        List<TeacherStudent> teacherStudents = teacherAndStudentMapper.selectByExample(example);
        if(teacherStudents!=null&&teacherStudents.size()>0){
            result=1;
            return result;
        }
        return result;
    }

    /**
     * 徒弟表评估
     * @param teaId
     * @param map
     * @return
     */
    @Override
    public Integer stuEva(Integer teaId, Map map) {
        Integer stuId=(Integer)map.get("stuId");
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("teaId",teaId);
        criteria.andEqualTo("stuId",stuId);
        List<TeacherStudent> teacherStudents = teacherAndStudentMapper.selectByExample(example);
        TeacherStudent teacherStudent=null;
        if(teacherStudents!=null&&teacherStudents.size()>0){
             teacherStudent = teacherStudents.get(0);
        }else{
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_EVA_FAILE_01.getCode(),ResultCodeEnum.TEA_EVA_FAILE_01.getMessage());
        }
        if(teacherStudent.getStatus()!=1){
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_EVA_FAILE_01.getCode(),ResultCodeEnum.TEA_EVA_FAILE_01.getMessage());
        }
        if(teacherStudent.getIsStuEva().equals(1)){
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_EVA_FAILE_02.getCode(),ResultCodeEnum.TEA_EVA_FAILE_02.getMessage());
        }
        User tea = userMapper.selectByPrimaryKey(teaId);
        User stu = userMapper.selectByPrimaryKey(stuId);
        Map<String, String> excelMap = new HashMap<String,String>();
        excelMap.put("stuName",stu.getUsername());
        excelMap.put("teaName",tea.getUsername());
        String temUrl= ReadPropertiesUtil.readUrl("studentTemUrl");
        String excleName=stu.getUsername()+"徒弟评估"+System.currentTimeMillis();
        Integer deptId = stu.getDeptId();
        Department department = departmentMapper.selectByPrimaryKey(deptId);
        String deptName = department.getName();
        String job = stu.getJob();
        Integer row1=(Integer) map.get("row1");
        Integer row2=(Integer) map.get("row2");
        Integer row3=(Integer) map.get("row3");
        Integer row4=(Integer) map.get("row4");
        Integer row5=(Integer) map.get("row5");
        Integer row6=(Integer) map.get("row6");
        Integer row7=(Integer) map.get("row7");
        Integer row8=(Integer) map.get("row8");
        Integer row9=(Integer) map.get("row9");
        Integer row10=(Integer) map.get("row10");
        Integer row11=row1+row2+row3+row4+row5+row6+row7+row8+row9+row10;
        excelMap.put("temUrl",temUrl);
        excelMap.put("excleName",excleName);
        excelMap.put("deptName",deptName);
        excelMap.put("job",job);
        excelMap.put("row1",row1+"");
        excelMap.put("row2",row2+"");
        excelMap.put("row3",row3+"");
        excelMap.put("row4",row4+"");
        excelMap.put("row5",row5+"");
        excelMap.put("row6",row6+"");
        excelMap.put("row7",row7+"");
        excelMap.put("row8",row8+"");
        excelMap.put("row9",row9+"");
        excelMap.put("row10",row10+"");
        excelMap.put("row11",row11+"");
        String stuEvaUrl="";
        try {
            stuEvaUrl=ExcelExporeUtil.createExcle(excelMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        StuEVA stuEVA = new StuEVA();
        stuEVA.setRow1(row1);
        stuEVA.setRow2(row2);
        stuEVA.setRow3(row3);
        stuEVA.setRow4(row4);
        stuEVA.setRow5(row5);
        stuEVA.setRow6(row6);
        stuEVA.setRow7(row7);
        stuEVA.setRow8(row8);
        stuEVA.setRow9(row9);
        stuEVA.setRow10(row10);
        stuEVA.setRow11(row11);
        stuEvaMapper.insertSelective(stuEVA);
        Integer stuEvaId = stuEVA.getId();
        teacherStudent.setStuEvaId(stuEvaId);
        teacherStudent.setStuEvaUrl(stuEvaUrl);
        teacherStudent.setStuEvaTime(new Date());
        teacherStudent.setIsStuEva(1);
        return teacherAndStudentMapper.updateByPrimaryKeySelective(teacherStudent);
    }

    /**
     * 导师评估表
     * @param stuId
     * @param map
     * @return
     */
    @Override
    public Integer teaEva(Integer stuId, Map map) {
        Integer teaId=(Integer)map.get("teaId");
        Example example = new Example(TeacherStudent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("teaId",teaId);
        criteria.andEqualTo("stuId",stuId);
        List<TeacherStudent> teacherStudents = teacherAndStudentMapper.selectByExample(example);
        TeacherStudent teacherStudent=null;
        if(teacherStudents!=null&&teacherStudents.size()>0){
            teacherStudent = teacherStudents.get(0);
        }else{
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_EVA_FAILE_03.getCode(),ResultCodeEnum.TEA_EVA_FAILE_03.getMessage());
        }
        if(teacherStudent.getStatus()!=1){
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_EVA_FAILE_03.getCode(),ResultCodeEnum.TEA_EVA_FAILE_03.getMessage());
        }
        if(teacherStudent.getIsTeaEva().equals(1)){
            throw new BusinessRuntimeException(ResultCodeEnum.TEA_EVA_FAILE_02.getCode(),ResultCodeEnum.TEA_EVA_FAILE_02.getMessage());
        }
        User tea = userMapper.selectByPrimaryKey(teaId);
        User stu = userMapper.selectByPrimaryKey(stuId);
        Map<String, String> excelMap = new HashMap<String,String>();
        excelMap.put("stuName",stu.getUsername());
        excelMap.put("teaName",tea.getUsername());
        String temUrl= ReadPropertiesUtil.readUrl("TeaTemUrl");
        String excleName=stu.getUsername()+"导师评估"+System.currentTimeMillis();
        Integer deptId = tea.getDeptId();
        Department department = departmentMapper.selectByPrimaryKey(deptId);
        String deptName = department.getName();
        String job = stu.getJob();
        Integer row1=(Integer) map.get("row1");
        Integer row2=(Integer) map.get("row2");
        Integer row3=(Integer) map.get("row3");
        Integer row4=(Integer) map.get("row4");
        Integer row5=(Integer) map.get("row5");
        Integer row6=(Integer) map.get("row6");
        Integer row7=(Integer) map.get("row7");
        Integer row8=(Integer) map.get("row8");
        Integer row9=(Integer) map.get("row9");
        Integer row10=(Integer) map.get("row10");
        excelMap.put("temUrl",temUrl);
        excelMap.put("excleName",excleName);
        excelMap.put("deptName",deptName);
        excelMap.put("job",job);
        excelMap.put("row1",row1+"");
        excelMap.put("row2",row2+"");
        excelMap.put("row3",row3+"");
        excelMap.put("row4",row4+"");
        excelMap.put("row5",row5+"");
        excelMap.put("row6",row6+"");
        excelMap.put("row7",row7+"");
        excelMap.put("row8",row8+"");
        excelMap.put("row9",row9+"");
        excelMap.put("row10",row10+"");
        String teaEvaUrl="";
        try {
            teaEvaUrl=ExcelExporeUtil.createExcle(excelMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        TeaEVA teaEVA = new TeaEVA();
        teaEVA.setRow1(row1);
        teaEVA.setRow2(row2);
        teaEVA.setRow3(row3);
        teaEVA.setRow4(row4);
        teaEVA.setRow5(row5);
        teaEVA.setRow6(row6);
        teaEVA.setRow7(row7);
        teaEVA.setRow8(row8);
        teaEVA.setRow9(row9);
        teaEVA.setRow10(row10);
        teaEvaMapper.insertSelective(teaEVA);
        Integer teaEVAId = teaEVA.getId();
        teacherStudent.setTeaEvaId(teaEVAId);
        teacherStudent.setTeaEvaUrl(teaEvaUrl);
        teacherStudent.setTeaEvaTime(new Date()) ;
        teacherStudent.setIsTeaEva(1);
        return teacherAndStudentMapper.updateByPrimaryKeySelective(teacherStudent);
    }

    /**
     * 学生导师评估
     * @param evaFront
     * @return
     */
    @Override
    public EVAResult getEVAResult(EVAFront evaFront) {
        PageHelper.startPage(evaFront.getPage(),evaFront.getPageSize());
        Page<EVAEntity> pages =(Page<EVAEntity>) daiTuTeaMapper.selectEVAReult(evaFront.getTeaName());
        List<EVAEntity> result = pages.getResult();
        int size = result.size();
        EVAResult evaResult = new EVAResult();
        evaResult.setTotals(size);
        if(size>0){
            List<Integer> teaIds = result.stream().map(x -> x.getTeaId()).collect(Collectors.toList());
            List<Integer> stuId = result.stream().map(x -> x.getStuId()).collect(Collectors.toList());
            List<UserMessage> teas = userMapper.selectByList(teaIds);
            List<UserMessage> stus = userMapper.selectByList(stuId);
            List<EVAEntity> evaEntities = new ArrayList<>();
            for (EVAEntity evaEntity : result) {
                for (UserMessage tea : teas) {
                    if(tea.getId().equals(evaEntity.getTeaId())){
                        evaEntity.setTeaName(tea.getUsername());
                    }
                }
                for (UserMessage stu : stus) {
                    if(stu.getId().equals(evaEntity.getStuId())){
                        evaEntity.setStuName(stu.getUsername());
                    }
                }
                evaEntities.add(evaEntity);
            }
            evaResult.setEvaEntityList(evaEntities);
        }

        return evaResult;
    }
}
